<template>
  <el-row
    type="flex"
    justify="space-between"
    align="middle"
    style="height: 40px"
  >
    <el-col>
      <span>{{ departs.name }}</span>
    </el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <!-- 两个内容 -->
        <el-col>{{ departs.manager }}</el-col>
        <el-col>
          <!-- 下拉菜单 element -->
          <el-dropdown @command="handleCommand">
            <span> 操作<i class="el-icon-arrow-down" /> </span>
            <!-- 下拉菜单 -->
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="isType" command="see"
                >查看部门</el-dropdown-item
              >
              <el-dropdown-item v-if="isType" command="del"
                >删除部门</el-dropdown-item
              >
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDepartments } from "@/api/departments";
export default {
  props: {
    departs: {
      type: Object,
      required: true,
    },
    isType: {
      type: Boolean,
      default: true,
    },
  },
  methods: {
    handleCommand(type) {
      if (type === "add") {
        this.$emit("addDepart", this.departs, type);

        // 添加部门
      } else if (type === "see") {
        this.$emit("addDepart", this.departs, type);
        // 查看部门
      } else {
        // 删除部门
        this.$confirm("是否删除此条记录?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          await delDepartments(this.departs.id);
          this.$emit("delDepart");
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        });
      }
    },
  },
};
</script>

<style>
</style>